<!DOCTYPE html>
<html lang="en">
<head><meta charset="UTF-8"><title>仓储系统</title>
  <link rel="stylesheet" href="css/base.css">

</head>
<body>
  <div class="all">
      <div class="top">
          <div class="logo">
              <img style="vertical-align: middle"
                   src="images/logo.jpg" width="32" />
              仓储系统</div>
          <div class="other">
              <div class="notice_icon"><span>5</span>
                  <img src="images/notice.png" width="24" style="margin-top:2px;" />
              </div>
              <div class="user_info"><img width="30" src="images/touxiang.png" />
              </div>
          </div>
      </div>
      <div class="cnt">
         <script src="js/nav.js"></script>
          <script>
              setColor(3)
          </script>
    <div class="main">

      <div class="main_top">
        <h3>供应商搜索(鲁涛)</h3>
        <div class="search">
          <input id="stitle"  />
          <img id="search_btn"
               onclick="search()"
               width="16" src="images/search.png" />
        </div>
        <div class="btn" id="add_btn" onclick="add()">添加供应商</div>
        <div class="btn" id="save_btn" style="display:none" onclick="save()">保存</div>
        <div class="btn" id="nosave_btn" style="display:none" onclick="nosave()">取消</div>
      </div>

      <div id="list_div">

      </div>

      <div id="loading" style="text-align: center;height:300px;line-height: 300px">
        <img src="images/zd2.webp"/>
      </div>
      <div id="add_div" style="display:none;">
        <div class="input_div">供应商类型：
          <select id="gysType">
            <option value="总部公告">厂家</option>
            <option value="战区公告">外部</option>
          </select>
        </div>
        <div class="input_div">供应商名称：<input id="gysName"  /></div>
        <div class="input_div">供应商编码：<input  id="gysCode">

      </div>
        <div class="input_div">负责人：<input id="ren"  /></div>
        <div class="input_div">负责人联系方式：<input id="renMobile"  /></div>

    </div>
      <div id="data" style="display:none;"></div>
  </div>



  <div class="bot">
    Copyright © 2022-2023 XINLING. All Rights Reserved.
  </div>
</div>
<script src="js/base.js"></script>

<script>
    //showDate();
    var gys = [];
    loadData();


    function showData(arr){
        list_div.innerHTML = "";
        if(arr.length==0){
            list_div.innerHTML = "暂无数据";
            return;
        }
        var allhtml = "";
        allhtml += "<table width='100%'><tr>" +
            "<th>供应商名称</th><th>供应商类型</th><th>供应商编码</th><th>负责人</th>" +
            "<th>负责人联系方式</th></tr>";
        for(var i=arr.length-1;i>=0;i--){
            var a = arr[i];
            allhtml +=
                "<tr class='list'>" +
                "<td class='ntitle'>"+a.gysName+"</td>" +
                "<td class='ntitle'>"+a.gysType+"</td>" +
                "<td class='ntitle'>"+a.gysCode+"</td>" +
                "<td class='ntitle'>"+a.ren+"</td>" +
                "<td class='ntitle'>"+a.renMobile+"</td>" +
                "</tr>";
        }
        allhtml += "</table>";
        list_div.innerHTML = allhtml;
    }

     for(var i=arr.length-1;i>=0;i--){
        var a = arr[i];

        allhtml +=
            "<tr class='list'>" +
            "<td class='ntitle'>"+a.gysName+"</td>" +
            "<td class='ntitle'>"+a.gysType+"</td>" +
            "<td class='ntitle'>"+a.gysCode+"</td>" +
            "<td class='ntitle'>"+a.ren+"</td>" +
            "<td class='ntitle'>"+a.renMobile+"</td>" +
            "<td class='ntitle'><a class='edit_a' href='#'>编辑</a>" +
            "<a class='del_a' onclick='del("+a.id+")' href='javascript:;'>删除</a></td>" +
            "</tr>";
    }
    allhtml += "</table>";
    list_div.innerHTML = allhtml;


    function search(){
        loadData({title:stitle.value});
    }


function loadData(data){
    list_div.innerHTML = "";
    loading.style.display = "block";
    ajax("/find_all_gys",data,function(data){
        datas = data;
        showData(datas);
         loading.style.display = "none";
    });
}


   function save() {
    ajax("/add_gys",{
        gysName: gysName.value,
        gysCode: gysCode.value,
        gysType: gysType.value,
        people: ren.value,
        peopleMobile: renMobile.value
    }, function (data) {
        alert("新增成功！");
        loadData();
        add_div.style.display = "none";
        list_div.style.display = "block";
        save_btn.style.display = "none";
        add_btn.style.display = "block";
    })

}

    function add(){
    data.style.display="none"
        add_div.style.display = "block";

        list_div.style.display = "none";

        save_btn.style.display = "block";

        add_btn.style.display = "none";

        nosave_btn.style.display="block"


    }
     function nosave(){
        add_div.style.display = "none";

        list_div.style.display = "block";

        save_btn.style.display = "none";

        add_btn.style.display = "block";

        nosave_btn.style.display="none"


    }


</script>

  </div>

</body>
</html>